<template>
  <div>
      <h1>个人类及公司类产品占比</h1>
      <div id="main" style="width: 600px; height: 400px; margin-left:26%"></div>
  </div>
</template>

<script>
export default {
  name: "c1",

  data() {
    return {
      classifyByType: [],
    };
  },

  mounted() {
    this.classify();
  },

  methods: {
    classify() {
      this.$axios.get("/products/countByType").then((res) => {
        this.classifyByType = res.data.data.classifyByType;
        this.getChar();
      });
    },

    getChar() {
      // 基于准备好的dom，初始化echarts实例
      var myChart = this.$echarts.init(document.getElementById("main"));
      // 指定图表的配置项和数据
      var option = {
        tooltip: {
          trigger: "item",
        },
        legend: {
          top: "5%",
          left: "center",
        },
        series: [
          {
            name: "Access From",
            type: "pie",
            radius: ["40%", "70%"],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: "#fff",
              borderWidth: 2,
            },
            label: {
              show: false,
              position: "center",
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 40,
                fontWeight: "bold",
              },
            },
            labelLine: {
              show: false,
            },
            data: this.classifyByType,
          },
        ],
      };
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
    },
  },
};
</script>